<template>
  <el-select v-model="value" :placeholder="props.placeholder" clearable filterable @change="change">
    <el-option v-for="item in countryOptions" :key="item.country" :label="item.name" :value="item.country" />
  </el-select>
</template>
<script setup>
import useCommonStore from "@/store/modules/common";
const commonStore = useCommonStore();
const countryOptions = computed(() => {
  if (!commonStore.countryOptions) {
    commonStore.getCountryList()
  }
  return commonStore.countryOptions
});
const props = defineProps({
  modelValue: [String, Number, Array],
  placeholder: {
    type: String,
    default: '请选择',
  }
});

const value = ref()
watch(() => props.modelValue, (val) => {
  value.value = val
})
const emit = defineEmits(['update:modelValue','change'])
const change = (val) => {
  const item = countryOptions.value.find(i => i.logistics_id == val)
  emit('update:modelValue', val)
  emit('change', item?.name)

}

</script>